// pages/home/homeLeiBo/personalHousing/personalHousing.js
import Https from "../../../utils/api.js"
const http = new Https
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		imgs: "../../../../assets/home/butie.png",
		collect: false,
		//楼盘经纬度
		markers: [],
		// 轮播图
		images: [
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
			"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4018216757,316269704&fm=26&gp=0.jpg",
		],
		houseType: [],
		building: {},
		houseInfo: [],
		// 周边新房
		nearbyNewHouse: [{
			id: '1',
			zd: '1',
			img: '/assets/home/homeListItem/home01.png',
			title: '合力达卓越南城',
			stmel: '北海区',
			stmels: '东路101号',
			number: '15000',
			specifications: '2室1厅',
			squaremeter: '67.7',
			homesuper: '精装修',
			q1: "海景",
			q2: "别墅",
			homeN: 1,
			homeS: "停售"
		},
		{
			id: '2',
			img: '/assets/home/homeListItem/home01.png',
			title: '中心海城',
			stmel: '途家丛',
			stmels: '赤岭路110路',
			number: '11000',
			q1: "海景",
			q2: "别墅",
			homeN: 2,
			homeS: "在售"
		},
		{
			id: '3',
			img: '/assets/home/homeListItem/home01.png',
			title: '广夏大楼',
			stmel: '梅溪湖',
			stmels: '鼎奥国际',
			number: '14000',
			q1: "海景",
			q2: "别墅",
			homeN: 2,
			homeS: "在售"
		},
		{
			id: '4',
			img: '/assets/home/homeListItem/home01.png',
			title: '溪岛精装套三，靠地铁',
			stmel: '长沙县',
			stmels: '小遂溪岛',
			number: '90000',
			q1: "海景",
			q2: "别墅",
			homeN: 2,
			homeS: "在售"
		}
		]
	},
	onLoad(options) {
		console.log(options)
		var buildingId = options.id
		var markers = []
		http.request('building/building', {
			id: buildingId
		}).then(res => {
			console.log(res)
			var marker = {
				id: res.data.id,
				latitude: res.data.latitude,
				longitude: res.data.longitude,
				iconPath: "../../../assets/biaojidianwei.png",
				width: 30,
				height: 30,
				label: {
					content: res.data.title, //文本
					color: '#FF0202', //文本颜色
					borderRadius: 3, //边框圆角
					borderWidth: 1, //边框宽度
					borderColor: '#FF0202', //边框颜色
					bgColor: '#ffffff', //背景色
					padding: 5, //文本边缘留白
					textAlign: 'center' //文本对齐方式。有效值: left, right, center
			}
		}
		markers.push(marker)
			var houseInfo = [];
			houseInfo.push({
				name: "用途",
				price: res.data.tags
			}, {
				name: "产权",
				price: "2019.07.19"
			}, {
				name: "地址",
				price: res.data.address
			})
			var data = res.data
			var typeArr = res.data.type.split(",")
			var type = ""
			typeArr.forEach(element => {
				type += element + "室" + "/"
			});
			type = type.slice(0, -1)
			data.type = type
			console.log(data)
			this.setData({
				building: data,
				houseInfo:houseInfo,
				markers:markers
			})
		})

		http.request('building/house/id', {
			id: buildingId
		}).then(res => {
			console.log(res)
			var data = res.data
			var houseType = []
			var building = {}
			data.forEach(element => {
				var info = {
					image: "https://ke-image.ljcdn.com/hdic-frame/0c1a660480312a4827bb6815a610ecf6.jpg.1000x.jpg",
					name: element.house_type.name,
					area: element.area,
					price: element.price,
					status: element.sale_status
				}
				building = element.building
				houseType.push(info)
			});
			this.setData({
				houseType: houseType
			})
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	goodHouse() {
		let pages = getCurrentPages();
		let currPage = pages[pages.length - 1];
		let prevPage = pages[pages.length - 2];
		prevPage.setData({
			currentInexs: 1,
		});
		wx.navigateBack({
			delta: 1
		})
	},
	personal() {
		wx.navigateBack({
			delta: 1
		})
	},
	newHouse() {
		wx.navigateTo({
			url: "/pages/home/newHouseList/newHouseList"
		})
	},
	goVR(){
		wx.navigateTo({
			url: "/pages/vrView/vrView"
		})
	},
	collect() {
		if (this.data.collect) {
			this.setData({
				collect: false
			});
			wx.showToast({
				title: "取消收藏成功",
				icon: "none"
			})
		} else {
			this.setData({
				collect: true
			});
			wx.showToast({
				title: "收藏成功",
				icon: "none"
			})
		}
	},
	previewImage() {
		let that = this;
		wx.previewImage({
			urls: that.data.images
		})
	},



	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})
